package net.ebakker.feededitor.database;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import net.ebakker.feededitor.Preferences;

public class PostgresInserter {

	public void insert(String title, Connection conn, Preferences pref) throws SQLException,
			UnsupportedEncodingException {
		String stm = "INSERT INTO ttrss_feeds(" + //
				"owner_uid, title, cat_id, feed_url, update_interval," + //
				"purge_interval, site_url)" + //
				"VALUES (?, ?, ?, ?, ?, ?, ?)";

		String url =
				"http://pretome.info/rss.php?st=1&tf=all&search="
						+ URLEncoder.encode(title, "UTF-8")
						+ "&tags=x264&tf=all&cat[]=19&sort=0&type=d&key=" + pref.getPretomeKey()
						+ "&full";

		PreparedStatement statement = conn.prepareStatement(stm);
		statement.setInt(1, 1);
		statement.setString(2, title);
		statement.setInt(3, 2);
		statement.setString(4, url);
		statement.setInt(5, 240);
		statement.setInt(6, 5);
		statement.setString(7, "http://pretome.info/rss.php");
		statement.executeUpdate();
	}
}
